package com.huirui.server.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 用户信息 VO（数据传输对象）
 * 用于前端展示用户核心信息，包含基础信息、账户信息、时间信息
 */
@Data
@Schema(
        name = "UserVo",  // Swagger 文档中显示的模型名称
        description = "用户信息展示对象",  // 模型描述
        example = """
                {
                  "userId": 10001,
                  "userName": "张三",
                  "userAvatar": "https://example.com/avatars/zhangsan.jpg",
                  "phoneNumber": "13800138000",
                  "balance": 999.99,
                  "consumptionAmount": 2568.50,
                  "registrationDate": "2025-01-15T08:30:45",
                  "lastLoginDate": "2025-11-13T14:22:36"
                }"""  // 模型完整示例（支持多行字符串，增强可读性）
)
@Builder
public class UserVo {

    @Schema(
            description = "用户唯一标识",  // 字段描述
            example = "10001",  // 字段示例值
            type = "integer",  // 字段类型（默认自动推导，可显式指定）
            format = "int64",  // 数据格式（Long 对应 int64）
            requiredMode = Schema.RequiredMode.NOT_REQUIRED  // 是否必填（默认非必填，可省略）
    )
    private Long userId;

    @Schema(
            description = "用户名",
            example = "张三",
            maxLength = 20,  // 最大长度限制
            minLength = 2,   // 最小长度限制
            pattern = "^[\\u4e00-\\u9fa5a-zA-Z0-9_]{2,20}$"  // 字段格式正则（中文、字母、数字、下划线）
    )
    private String userName;

    @Schema(
            description = "用户头像 URL",
            example = "https://example.com/avatars/zhangsan.jpg",
            format = "uri-reference"  // 标识为 URL 格式（Swagger 文档会提示格式要求）
    )
    private String userAvatar;

    @Schema(
            description = "手机号码",
            example = "13800138000",
            pattern = "^1[3-9]\\d{9}$",  // 手机号正则校验
            maxLength = 11,
            minLength = 11
    )
    private String phoneNumber;

    @Schema(
            description = "账户余额（元）",
            example = "999.99",
            type = "number",
            format = "decimal",  // BigDecimal 对应 decimal 格式
            minimum = "0" // 最小值限制（余额不能为负）
    )
    private BigDecimal balance;

    @Schema(
            description = "累计消费金额（元）",
            example = "2568.50",
            type = "number",
            format = "decimal",
            minimum = "0"
    )
    private BigDecimal consumptionAmount;

    @Schema(
            description = "注册时间",
            example = "2025-01-15T08:30:45",  // LocalDateTime 标准格式（ISO 8601）
            type = "string",
            format = "date-time"  // 标识为日期时间格式（Swagger 会提供日期选择器）
    )
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime registrationDate;

    @Schema(
            description = "最后登录时间",
            example = "2025-11-13T14:22:36",
            type = "string",
            format = "date-time"
    )
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastLoginDate;
}
